<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="Users.aspx.cs" Inherits="Admin_Users_Users" Title="APM - Users" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <script type="text/javascript">
function toggle(tab) {
	for (i = 0; i < tab.parentNode.parentNode.childNodes.length; i++) {
		if (tab.parentNode.parentNode.childNodes[i].nodeName == "LI")
				tab.parentNode.parentNode.childNodes[i].className = "";
	}
	tab.parentNode.className = "active";
}

function showMessage()
{
alert("sdfdf");
    document.getElementById("lblMessage").style.visibility = "visible";
}
    </script>

    <ul id="path">
        <li><a href="../../Home.aspx">Home</a> &gt;</li>
        <li>Administration &gt;</li>
        <li>Users</li>
    </ul>
    <h3 class="users">
        <span>Users</span></h3>
    <div id="content">
        <div id="tabgroup">
            <ul class="tabs">
                <li id="addl" runat="server" class="active">
                    <asp:LinkButton ID="lbnew" runat="server" CausesValidation="False" OnClick="lbnew_Click"
                        ToolTip="For adding new users.">Add New User</asp:LinkButton></li>
                <li id="editl" runat="server">
                    <asp:LinkButton ID="lbedit" runat="server" CausesValidation="False" OnClick="lbedit_Click"
                        ToolTip="For editing existing users.">Edit User</asp:LinkButton>
                </li>
            </ul>
            <div class="frame" style="min-height: 550px;">
                <asp:Panel ID="pnlSearch" runat="server" Width="100%" Visible="false">
                    <table border="0" cellpadding="0" cellspacing="0" class="table" width="100%">
                        <tr align="center">
                            <th colspan="2">
                                Quick Search
                            </th>
                        </tr>
                        <tr>
                            <td align="left" style="padding: 0 0 0 0;">
                                <asp:RadioButtonList ToolTip="Select to search by User Name or by User Alias." runat="server"
                                    ID="rdsearchType" AutoPostBack="false" TextAlign="Right" RepeatDirection="Horizontal">
                                    <asp:ListItem Selected="true" Value="0"> Search by User Name</asp:ListItem>
                                    <asp:ListItem Value="1">Search by User Alias</asp:ListItem>
                                </asp:RadioButtonList>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" style="padding: 0 0 0 0;">
                                <table border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td align="left">
                                            <asp:TextBox ID="txtSearch" runat="server" MaxLength="50" ValidationGroup="search"
                                                Width="220" CssClass="input">
                                            </asp:TextBox>
                                            <asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="Search"
                                                ValidationGroup="search" /></td>
                                        <td>
                                            &nbsp;&nbsp;Example - Sara Hettich or sara</td>
                                    </tr>
                                </table>
                                <asp:RequiredFieldValidator ID="reqAppName" runat="server" ControlToValidate="txtSearch"
                                    Display="None" ErrorMessage="Required Field: User Name/Alias" SetFocusOnError="True"
                                    ValidationGroup="search">
                                </asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ID="reguAppName" runat="server" ControlToValidate="txtSearch"
                                    Display="None" ErrorMessage="Invalid Input: User Name/Alias" ValidationExpression="<%$ AppSettings:UserNameRegEx %>"
                                    ValidationGroup="search">
                                </asp:RegularExpressionValidator>
                            </td>
                        </tr>
                        <tr>
                            <td align="left">
                                <asp:Label ID="lblResult" runat="server" Text="Select User" Visible="false"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td align="left">
                                <asp:ListBox ID="lstUserNames" runat="server" DataTextField="UserNameAlias" DataValueField="UserGUID"
                                    Rows="5" Visible="False" Width="275"></asp:ListBox>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" colspan="1">
                                <asp:Button ID="btnGo" runat="server" OnClick="GoClick" Text="Select" Visible="false" />
                                <asp:ValidationSummary ID="commonValidation" runat="server" DisplayMode="BulletList"
                                    HeaderText="Please correct the following:" ShowMessageBox="true" ShowSummary="false"
                                    ValidationGroup="search"></asp:ValidationSummary>
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
                <asp:Panel ID="pnlUser" runat="server" Width ="100%">
                    <table border="0" width="100%">
                        <tr>
                            <td>
                                User Alias
                            </td>
                            <td>
                                <table cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td>
                                            <asp:TextBox ID="txtUserAlias" runat="server" MaxLength="50" CssClass="input" ValidationGroup="useralias"
                                                ToolTip="Enter Alias of the new user. To Search the user in Active Directory minimun of 3 characters are required."></asp:TextBox>
                                            <asp:Button ID="btnFindUser" runat="server" OnClick="FindUserClick" ToolTip="Click this button to find the users in Active Directory. Minimun of 3 characters are required for the search to begin."
                                                Text="Find User" ValidationGroup="useralias"  />                                            
                                        </td>
                                        <td>
                                            &nbsp;&nbsp;Example - sara. </td>
                                    </tr>
                                </table>
                                <asp:RequiredFieldValidator ID="reqUserAlias" runat="server" SetFocusOnError="true"
                                    Display="None" ControlToValidate="txtUserAlias" ErrorMessage=" Required Field: User Alias "
                                    ValidationGroup="user"></asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtUserAlias"
                                    ErrorMessage="Invalid Input: User Alias" ValidationExpression="<%$ AppSettings:UserNameRegEx %>"
                                    Display="None" ValidationGroup="user"></asp:RegularExpressionValidator>
                                <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtUserAlias"
                                    Display="None" ErrorMessage="Invalid Input: User Alias" SetFocusOnError="True"
                                    ValidationExpression="<%$ AppSettings:UserNameRegEx %>" ValidationGroup="useralias"></asp:RegularExpressionValidator>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" SetFocusOnError="true"
                                    Display="None" ControlToValidate="txtUserAlias" ErrorMessage=" Required Field: User Alias "
                                    ValidationGroup="useralias"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                User Name
                            </td>
                            <td>
                                <table cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td>
                                            <asp:TextBox ID="txtUserID" Visible="false" runat="server"></asp:TextBox>
                                            <asp:TextBox CssClass="input" ID="txtUserName" runat="server" MaxLength="100" ValidationGroup="user"></asp:TextBox></td>
                                        <td>
                                            &nbsp;&nbsp;Example - Sara Hettich</td>
                                    </tr>
                                </table>
                                <asp:RequiredFieldValidator ID="reqUsrName" runat="server" SetFocusOnError="true"
                                    Display="None" ControlToValidate="txtUserName" ErrorMessage=" Required Field: User Name "
                                    ValidationGroup="user"></asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ID="revUserName" runat="server" ControlToValidate="txtUserName"
                                    ErrorMessage="Invalid Input: User Name" ValidationExpression="<%$ AppSettings:UserNameRegEx %>"
                                    Display="None" ValidationGroup="user"></asp:RegularExpressionValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                User E-mail
                            </td>
                            <td>
                                <table cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td>
                                            <asp:TextBox ID="txtUserEmail" runat="server" MaxLength="100" CssClass="input" ValidationGroup="user"></asp:TextBox></td>
                                        <td>
                                            &nbsp;&nbsp;Example - sara@contoso.com</td>
                                    </tr>
                                </table>
                                <asp:RequiredFieldValidator ID="reqUserEmail" runat="server" SetFocusOnError="true"
                                    ValidationGroup="user" Display="None" ControlToValidate="txtUserEmail" ErrorMessage=" Required Field: User E-mail "></asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ID="revEmail" runat="server" ControlToValidate="txtUserEmail"
                                    ValidationGroup="user" Display="None" ErrorMessage="Invalid Input: User E-mail"
                                    ValidationExpression="<%$ AppSettings:UserEmailRegEx %>"></asp:RegularExpressionValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Admin
                            </td>
                            <td>
                                <asp:CheckBox ID="chkIsAdmin" runat="server" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Active
                            </td>
                            <td>
                                <asp:CheckBox ID="chkActive" runat="server" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:ValidationSummary ID="vsUser" runat="server" HeaderText="Please correct the following:"
                                    ShowMessageBox="true" ShowSummary="false" DisplayMode="BulletList" ValidationGroup="user" />
                                <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Please correct the following:"
                                    ShowMessageBox="true" ShowSummary="false" DisplayMode="BulletList" ValidationGroup="useralias" />
                                <asp:Button ID="btnSubmit" Text="Submit" OnClick="SubmitClick" runat="server" ValidationGroup="user"  ToolTip ="Click on the button to Add or Update the user in the system." />
                                <asp:Button ID="btnCancel" Text="Cancel" OnClick="CancelClick" runat="server" Visible="false"  />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                &nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:GridView Width="100%" Caption="List of Users (Maximum Users that can returned from Active Directory are 100)"
                                    CaptionAlign="Left" AllowPaging="True" PageSize="15" EmptyDataText="No users found that match your search criteria."
                                    DataKeyNames="Alias" Visible="true" ToolTip="This table displays all the users found for the search criteria."
                                    ID="gridUserSearchEdit" runat="server" AutoGenerateColumns="False" OnRowCommand="gridUserSearchEdit_RowCommand"
                                    CssClass="table" OnPageIndexChanging="gridUserSearchEdit_PageIndexChanging">
                                    <PagerSettings Position="TopAndBottom" PageButtonCount="10" />
                                    <PagerStyle HorizontalAlign="Right" ForeColor="Black" />
                                    <AlternatingRowStyle CssClass="alternate" />
                                    <EmptyDataRowStyle BackColor="#C4D7D6" />
                                    <Columns>
                                        <asp:ButtonField ButtonType="Link" HeaderText="User Alias" DataTextField="Alias"
                                            ItemStyle-Width="200px" CommandName="select">
                                            <ItemStyle Wrap="True" />
                                            <HeaderStyle Font-Bold="False" HorizontalAlign="Left" />
                                        </asp:ButtonField>
                                        <asp:BoundField HeaderText="User Name" DataField="Name" ItemStyle-Width="200px" HtmlEncode="true">
                                            <ItemStyle Wrap="True" />
                                            <HeaderStyle Font-Bold="False" HorizontalAlign="Left" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="Email Address" DataField="Email" HtmlEncode="true">
                                            <ItemStyle Wrap="True" />
                                            <HeaderStyle Font-Bold="False" HorizontalAlign="Left" />
                                        </asp:BoundField>
                                    </Columns>
                                </asp:GridView>
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
            </div>
        </div>
    </div>
</asp:Content>
